package com.beiing.leafchat.renderer;


import com.beiing.leafchat.bean.Axis;
import com.beiing.leafchat.bean.PointValue;
import com.beiing.leafchat.bean.Square;
import com.beiing.leafchat.support.LeafUtil;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.agp.utils.RectFloat;
import ohos.app.Context;

import java.util.List;

/**
 * Created by chenliu on 2017/1/10.<br/>
 * 描述：
 * </br>
 */

public class LeafSquareRenderer extends AbsRenderer {

    public LeafSquareRenderer(Context context, Component view) {
        super(context, view);
    }

    public void drawSquares(Canvas canvas, Square square, Axis axisX) {
        if (square != null) {
            //1.画直方图边界
            linePaint.setColor(new Color(square.getBorderColor()));
            if (!square.isFill()) {
                linePaint.setStrokeWidth(LeafUtil.dp2px(mContext, square.getBorderWidth()));
                linePaint.setStyle(Paint.Style.STROKE_STYLE);
            }
            List<PointValue> values = square.getValues();
            float width = LeafUtil.dp2px(mContext, square.getWidth());
            for (PointValue point : values) {
                RectFloat rectF = new RectFloat(LeafUtil.add(point.getOriginX(), -width / 2),
                        point.getOriginY(), LeafUtil.add(point.getOriginX(), width / 2), axisX.getStartY());

                canvas.drawRect(rectF, linePaint);
            }
        }
    }


}
